from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-26 14:02:17.985728
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Thu, 26, May, 2022
Time: 14:02:25
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.4309
Nobs: 668.000 HQIC: -49.8027
Log likelihood: 8271.97 FPE: 1.85723e-22
AIC: -50.0378 Det(Omega_mle): 1.62475e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.309663 0.059812 5.177 0.000
L1.Burgenland 0.107907 0.038620 2.794 0.005
L1.Kärnten -0.109842 0.020297 -5.412 0.000
L1.Niederösterreich 0.201269 0.080369 2.504 0.012
L1.Oberösterreich 0.124695 0.079564 1.567 0.117
L1.Salzburg 0.256095 0.041066 6.236 0.000
L1.Steiermark 0.043763 0.053823 0.813 0.416
L1.Tirol 0.104196 0.043569 2.392 0.017
L1.Vorarlberg -0.063999 0.038488 -1.663 0.096
L1.Wien 0.031127 0.070416 0.442 0.658
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.039867 0.127361 0.313 0.754
L1.Burgenland -0.029614 0.082236 -0.360 0.719
L1.Kärnten 0.040388 0.043219 0.935 0.350
L1.Niederösterreich -0.180181 0.171135 -1.053 0.292
L1.Oberösterreich 0.445627 0.169421 2.630 0.009
L1.Salzburg 0.284451 0.087444 3.253 0.001
L1.Steiermark 0.108388 0.114609 0.946 0.344
L1.Tirol 0.314809 0.092774 3.393 0.001
L1.Vorarlberg 0.021812 0.081954 0.266 0.790
L1.Wien -0.037914 0.149942 -0.253 0.800
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.184599 0.030744 6.004 0.000
L1.Burgenland 0.089949 0.019851 4.531 0.000
L1.Kärnten -0.007980 0.010433 -0.765 0.444
L1.Niederösterreich 0.256517 0.041310 6.210 0.000
L1.Oberösterreich 0.154922 0.040897 3.788 0.000
L1.Salzburg 0.043189 0.021108 2.046 0.041
L1.Steiermark 0.024616 0.027665 0.890 0.374
L1.Tirol 0.085709 0.022395 3.827 0.000
L1.Vorarlberg 0.052397 0.019783 2.649 0.008
L1.Wien 0.117116 0.036195 3.236 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.110159 0.030750 3.582 0.000
L1.Burgenland 0.045974 0.019855 2.316 0.021
L1.Kärnten -0.014157 0.010435 -1.357 0.175
L1.Niederösterreich 0.185591 0.041318 4.492 0.000
L1.Oberösterreich 0.326786 0.040904 7.989 0.000
L1.Salzburg 0.101889 0.021112 4.826 0.000
L1.Steiermark 0.108977 0.027671 3.938 0.000
L1.Tirol 0.096878 0.022399 4.325 0.000
L1.Vorarlberg 0.059146 0.019787 2.989 0.003
L1.Wien -0.022183 0.036201 -0.613 0.540
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115415 0.057245 2.016 0.044
L1.Burgenland -0.044194 0.036963 -1.196 0.232
L1.Kärnten -0.046223 0.019426 -2.379 0.017
L1.Niederösterreich 0.140801 0.076920 1.830 0.067
L1.Oberösterreich 0.163479 0.076150 2.147 0.032
L1.Salzburg 0.281305 0.039304 7.157 0.000
L1.Steiermark 0.055041 0.051513 1.068 0.285
L1.Tirol 0.164755 0.041699 3.951 0.000
L1.Vorarlberg 0.094858 0.036836 2.575 0.010
L1.Wien 0.076969 0.067395 1.142 0.253
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.059383 0.045191 1.314 0.189
L1.Burgenland 0.032422 0.029179 1.111 0.267
L1.Kärnten 0.051485 0.015335 3.357 0.001
L1.Niederösterreich 0.206253 0.060723 3.397 0.001
L1.Oberösterreich 0.317674 0.060115 5.284 0.000
L1.Salzburg 0.041320 0.031028 1.332 0.183
L1.Steiermark 0.008614 0.040666 0.212 0.832
L1.Tirol 0.131746 0.032919 4.002 0.000
L1.Vorarlberg 0.065044 0.029079 2.237 0.025
L1.Wien 0.086746 0.053203 1.630 0.103
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.164639 0.054060 3.046 0.002
L1.Burgenland 0.008607 0.034906 0.247 0.805
L1.Kärnten -0.065079 0.018345 -3.548 0.000
L1.Niederösterreich -0.090865 0.072640 -1.251 0.211
L1.Oberösterreich 0.203956 0.071912 2.836 0.005
L1.Salzburg 0.053583 0.037117 1.444 0.149
L1.Steiermark 0.240972 0.048647 4.953 0.000
L1.Tirol 0.502593 0.039379 12.763 0.000
L1.Vorarlberg 0.059163 0.034786 1.701 0.089
L1.Wien -0.075584 0.063644 -1.188 0.235
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.145959 0.060110 2.428 0.015
L1.Burgenland 0.003744 0.038813 0.096 0.923
L1.Kärnten 0.060218 0.020398 2.952 0.003
L1.Niederösterreich 0.183147 0.080770 2.268 0.023
L1.Oberösterreich -0.057446 0.079961 -0.718 0.472
L1.Salzburg 0.206366 0.041271 5.000 0.000
L1.Steiermark 0.135414 0.054092 2.503 0.012
L1.Tirol 0.070848 0.043786 1.618 0.106
L1.Vorarlberg 0.143027 0.038680 3.698 0.000
L1.Wien 0.110332 0.070768 1.559 0.119
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.374055 0.035457 10.550 0.000
L1.Burgenland -0.000114 0.022894 -0.005 0.996
L1.Kärnten -0.022079 0.012032 -1.835 0.067
L1.Niederösterreich 0.215629 0.047644 4.526 0.000
L1.Oberösterreich 0.227135 0.047167 4.816 0.000
L1.Salzburg 0.039574 0.024344 1.626 0.104
L1.Steiermark -0.015207 0.031907 -0.477 0.634
L1.Tirol 0.095803 0.025828 3.709 0.000
L1.Vorarlberg 0.053254 0.022816 2.334 0.020
L1.Wien 0.033688 0.041744 0.807 0.420
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.037732 0.120346 0.174589 0.144439 0.102136 0.087747 0.041540 0.212528
Kärnten 0.037732 1.000000 -0.019101 0.135220 0.052795 0.091122 0.442012 -0.059200 0.093887
Niederösterreich 0.120346 -0.019101 1.000000 0.324197 0.131439 0.283779 0.076902 0.163245 0.302227
Oberösterreich 0.174589 0.135220 0.324197 1.000000 0.220687 0.309201 0.170425 0.152110 0.251809
Salzburg 0.144439 0.052795 0.131439 0.220687 1.000000 0.130842 0.099773 0.115451 0.130685
Steiermark 0.102136 0.091122 0.283779 0.309201 0.130842 1.000000 0.142264 0.120616 0.052798
Tirol 0.087747 0.442012 0.076902 0.170425 0.099773 0.142264 1.000000 0.072788 0.149598
Vorarlberg 0.041540 -0.059200 0.163245 0.152110 0.115451 0.120616 0.072788 1.000000 0.008658
Wien 0.212528 0.093887 0.302227 0.251809 0.130685 0.052798 0.149598 0.008658 1.000000